import showData from '../edit/show-data'
import editData from '../edit/edit-data'
import {fetchList,delObj} from '../../../api/finance-manage-charge'
// hxf-0731-引入vuex
import {mapState} from 'vuex'

export default {
    name: 'resource-manage',
    components: {showData, editData},
		provide () {
			return {
				initList: this.getListData
			};
		},
		beforeMount () {
			this.getListData();
		},
    data() {
        return {
            tableData: [],
						// 请求参数
						params: {
							current: 1,
							size: 20,
							engineeringName: ""
						},
						// 选中的数据
						selectDataArr: [],
						// 分页
						pager: {
							total: 0, // 总页数
							current: 1, // 当前页数
							size: 20 // 每页显示多少条
						},
						// 页面loading
						loading: false,
        }
    },
    computed: mapState({
        charge_project_type: state => {
            let data = state.dict.find(item => item.type === "charge_project_type") || {}
            let list = data.children || []
            return data.children || []
        },
    }),
    methods: {
				getListData (params = {}) {
					this.loading = true;
					let requestData = { ...this.params, ...params };
					fetchList(requestData)
						.then(res => {
							const { current, size, total, records } = res.data.data;
							this.tableData = records;
							this.params = requestData;
							this.pager = { total, current, size };
						})
						.finally(() => {
							this.loading = false;
						});
				},
        editData(item) {
            this.$refs.editData.show(item)
        },
        showData(item) {
            this.$refs.showData.show(item)
        },
        del() {
            if (this.selectDataArr.length === 0) {
                this.err('请选择要删除的收费项目设置')
            } else {
                this.confirm('删除确认', '您确定要删除该数据吗？', () => {
                    let ids = this.selectDataArr.map(item => item.chargeProjectId)
                    delObj(ids.join(',')).then(resp => {
                        if (resp.data.data) {
                            this.suc('删除成功')
                            this.getListData()
                        } else {
                            this.err('删除失败')
                        }
                    })
                })
            }
        },
				// 菜单点击监听
				handleMenuClick (type) {
					switch (type) {
						case "add":
							this.editData();
							break;
						case "delete":
							this.del();
							break;
						default:
							this.$message(type);
							break;
					}
				}
    }
}
